package com.thti.mecool.client.command.result.user;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.base.Cache;
import com.thti.mecool.client.command.ICommand;
import com.thti.mecool.client.protocol.user.UserResult;
import com.thti.mecool.client.service.Protocol;
import com.thti.mecool.client.util.Util;

public class LoginCommand implements ICommand {

	@Override
	public void doCommand(Object o) {
		UserResult userResult = (UserResult) o;
		if (userResult.getStatus() == 1) {
			System.out.println("user get ok!");
			 SharedPreferences save_LoginInfo =Cache.getmContext().getSharedPreferences("LocationService", 0); ;
			 Editor editor=save_LoginInfo.edit();
			 editor.putString("host", userResult.getMessageServer().get("host").toString());
			 editor.putInt("port", Integer.parseInt(userResult.getMessageServer().get("port").toString()));
			 Util.print("service: "+userResult.getMessageServer().get("service").toString());
			 editor.putString("service",userResult.getMessageServer().get("service").toString());
			 editor.putString("password",userResult.getMessageServer().get("password").toString());
			 Util.print("service: "+userResult.getMessageServer().get("password").toString());
			 editor.commit();
			 Util.print("port：  "+userResult.getMessageServer().get("port").toString());
			 BaseActivity.setCurrentUser(userResult.getUser());
		} else {
			BaseActivity.setCurrentMesg(userResult.getMsg());
		}

	}

	@Override
	public String getCommandID() {
		// TODO Auto-generated method stub
		return Protocol.getLogin;
	}

	@Override
	public Class<?> getCommandClass() {

		// TODO Auto-generated method stub
		return UserResult.class;
	}

}
